<template>
  <div>
    <van-form @submit="onSubmit">
      <van-nav-bar
        class="am-navbar"
        title="账号注册"
        left-arrow
        @click-left="onClickLeft"
      />
      <van-field
        class="Login_input__2pNlW"
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        class="Login_input__2pNlW"
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit">注册</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { register } from "@/api/user";

export default {
  name: "enroll-",

  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    async onSubmit(values) {
      // console.log("submit", values);
      const data = await register(values);
      if(data.status ===200){
      this.$toast.success("注册成功");
      this.$router.push("/login");
      }else{
        this.$toast('注册异常')
      }
      
      console.log(data);
    },
    onClickLeft() {
      this.$router.go(-1);
      this.$toast("返回");
    },
  },
};
</script>
